package fr.mywiki.business.utils;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * Static class which gives rapid access to the Java properties
 * of the application.
 *
 * @author Bernard Leckning
 * @version 04-07-2001
 * 
 * FIXME : java.util.MissingResourceException: Can't find bundle for base name config, locale fr_FR
 */
public final class ConfigManager {

  // Resource Bundles (string literals for localisation)
  public final static String CONFIG = "config";

  /**
   * A hash table of the <CODE>ResourceBundles</CODE>.
   */
  private static ResourceBundle properties;

  /**
   * Default constructor.
   */
  public ConfigManager() {}

  /**
   * Retourne la valeur de la cle dans le fichier .properties
   * @param   key  cle dont on cherche la valeur
   * @return  Valeur de la cle
   */
  public static String getProperty(String key) {
    String value = null;
    try {
      if ( properties == null ) {
      	properties = ResourceBundle.getBundle(CONFIG, new Locale("",""));
      }

      if(properties == null)
        throw new MissingResourceException("Resource CONFIG not found.", "java.util.ResourceBundle", "");

      value = properties.getString(key);
    }
    catch(Exception e) {
      e.printStackTrace();
    }
    return value;
  }

}